package linhnv.app;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

public class ListItems extends Activity{
	private ListView listView;
	private TextView textView;
	private LinearLayout layout;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		ImageAdapter.setListItem(this);
		Bundle bundle = getIntent().getExtras();
		//get type of database
		int id = bundle.getInt("id", 0);
		String name = bundle.getString("name");
		
		Log.d("linhnv","======================come here1==="+id);
		super.onCreate(savedInstanceState);
		
		Log.d("linhnv","======================come here2");
		
		//Remove title bar
		//this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		//Remove notification bar
		//this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

		setContentView(R.layout.list_view);
//		WebView wv = (WebView)findViewById(R.id.imageBanner);
//		wv.loadUrl("file:///android_asset/gif.html");
//		TextView txt = new TextView(this);
//		txt.setText(" Linhnv ");
//		
		layout = (LinearLayout)findViewById(R.id.mainLayout);
		listView = (ListView)findViewById(R.id.lstFilm);
		ProgressBar pgb =(ProgressBar)findViewById(R.id.emptyView);
		listView.setEmptyView(pgb);
//		listView.addHeaderView(txt);
		ListItemsAdapter mAdapter = new ListItemsAdapter(this, id);
		
		listView.setAdapter(mAdapter );
		//mAdapter.notifyDataSetChanged();
		Button btnBack = (Button)findViewById(R.id.btnBack);
		btnBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				AudioStreaming.getHomeSelf().reset();
			}
		});
		textView = (TextView) findViewById(R.id.txtContent);
		textView.setText(name);
		if(name == null || name.length() == 0)
		{
			textView.setText("Hot");
		}
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		Log.w("Linhnv","========================ondestroy");
		super.onDestroy();
	}

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		Log.w("Linhnv","=======================on back pressed");
		this.onDestroy();
		super.onBackPressed();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		Log.w("Linhnv","=======================on key down " + keyCode);
		return super.onKeyDown(keyCode, event);
	}

	public void show(int id, String name)
	{
		textView.setText(name);
		if(listView != null)
		{
			listView.removeAllViewsInLayout();
		}
		listView.setAdapter(new ListItemsAdapter(this, id));
	}
	public LinearLayout getLayout()
	{
		return layout;
	}
}
